<template>
  <!--个人中心--账号资料-->
  <div class="ziliao">
      <Tabs :animated="false" active-key="key1"  v-model="tab" @on-click="changeTab">
        <TabPane label="个人资料" key="key1">
          <div class="changeImg">
            <img class="preimg" src="../../assets/headdefault.png"  v-if="person.avatar === ''"/>
            <img class="preimg" :src="person.avatar" v-else/>
            <span class="upuser"><Upload  ref="headup"  :show-upload-list="false"  :format="['jpg','jpeg','png']" :headers="{Authorization: token}" action="/base/file/upload" :max-size="3072" :on-exceeded-size="handleMaxSize"  :on-success="headSuccess" :on-format-error="formatError">修改头像</Upload></span>
          </div>
          <div class="formWrapper">
            <Form :label-width="86" ref="personValidate" :model="person" :rules="personValidate">
              <FormItem label="姓名" prop="userName">
                <Input v-model="person.userName" placeholder="请输入您的姓名" :maxlength="10"/>
              </FormItem>
              <FormItem label="昵称" prop="nickName">
                <Input v-model="person.nickName" placeholder="请输入您的昵称" :maxlength="10"/>
              </FormItem>
              <FormItem label="手机号" prop="mobile">
                <Input v-model="person.mobile" :maxlength="11" ref="tele"  disabled @on-keyup="validateTel"/>
              </FormItem>
              <FormItem label="性别" prop="sex">
                <Select class="formWidth" placeholder="性别" v-model="person.sex">
                  <Option :value= 1 >女</Option>
                  <Option :value= 2 >男</Option>
                </Select>
              </FormItem>
              <FormItem label="生日" prop="birthday">
                <DatePicker type="date" placeholder="选择日期" placement="top" style="width: 244px" :value="person.birthday"
                            @on-change="getBirthday"></DatePicker>
              </FormItem>
              <FormItem label="邮箱" prop="email">
                <Input class="formWidth" placeholder="请输入您的邮箱" v-model="person.email" :maxlength="80"/>
              </FormItem>
             <!-- <FormItem label="公司" prop="company">
                <Input placeholder="请输入您的公司" v-model="person.company" :maxlength="22"/>
              </FormItem>
              <FormItem label="部门" prop="department">
                <Input placeholder="请输入您所在部门" v-model="person.department" :maxlength="45"/>
              </FormItem>
              <FormItem label="职位" prop="positionName">
                <Input placeholder="请输入您的职位" v-model="person.positionName" :maxlength="45"/>
              </FormItem>-->
              <div class="keepThis"><span class="keepBtn" @click="updateUserData">保存</span></div>
            </Form>
          </div>
        </TabPane>
        <TabPane label="教育经历">
          <ul class="inforList font14" >
            <li class="clearfix">
              <p class="listLeft">学校名称</p>
              <!--<p class="listRight rightSet" v-if="education.schoolName === undefined">无  <span class="suretips" v-if="education.isEducation === 1"><img src="../../assets/renzheng.png" alt="" width="70" ></span><span class="suretips" v-else><img src="../../assets/norenzheng.png" alt="" width="70" ></span></p>-->
              <p class="listRight rightSet" v-if="education.schoolName == 'undefined' || education.schoolName == ''">无  <!--<span class="suretips" v-if="education.isEducation === 1"><img src="../../assets/renzheng.png" alt="" width="70" ></span><span class="suretips" v-else><img src="../../assets/nopass.png" alt="" width="70" ></span>--></p>
              <!--<p class="listRight rightSet" v-else>{{education.schoolName}}  <span class="suretips" v-if="education.isEducation === 1"><img src="../../assets/renzheng.png" alt="" width="70" ></span><span class="suretips" v-else><img src="../../assets/norenzheng.png" alt="" width="70" ></span></p>-->
              <p class="listRight rightSet" v-else>{{education.schoolName}}  <!--<span class="suretips" v-if="education.isEducation === 1"><img src="../../assets/renzheng.png" alt="" width="70" ></span><span class="suretips" v-else><img src="../../assets/nopass.png" alt="" width="70" ></span>--></p>
              <span  class="editorThis font14" @click="editEducation">编辑</span>
            </li>
            <li class="clearfix">
              <p class="listLeft">就读时间</p>
              <p class="listRight" v-if="education.studyStartTime == 'undefined' || education.studyStartTime == ''">无</p>
              <p class="listRight" v-else>{{education.studyStartTime}}-{{education.studyEndTime}}</p>
            </li>
            <li class="clearfix">
              <p class="listLeft">学历</p>
              <p class="listRight" v-if="education.education == 'undefined' || education.studyStartTime == ''">无</p>
              <p class="listRight" v-else>{{getEducation(education.education)}}</p>
            </li>
            <li class="clearfix">
              <p class="listLeft">专业</p>
              <p class="listRight" v-if="education.major == 'undefined' || education.major == ''">无</p>
              <p class="listRight" v-else>{{getMajor(education.major)}}</p>
            </li>
            <li class="clearfix">
              <p class="listLeft">是否统招</p>
              <p class="listRight" v-if="education.unified === 1">是</p>
              <p class="listRight" v-else>否</p>
            </li>
            <li class="clearfix">
              <p class="listLeft">证书编号</p>
              <p class="listRight" v-if="education.certificateNo == 'undefined' || education.certificateNo == ''">无</p>
              <p class="listRight" v-else>{{education.certificateNo}}</p>
            </li>
            <li>
              <img class="showimg" :src="education.diploma"/>
            </li>
            <li class="clearfix">
              <p class="listLeft">职称</p>
              <p class="listRight" v-if="education.academicTitle == 'undefined' || education.academicTitle == ''">无</p>
              <p class="listRight" v-else>{{education.academicTitle}}</p>
            </li>
            <li class="clearfix">
              <p class="listLeft">级别</p>
              <p class="listRight" v-if="education.grade == 'undefined' || education.grade == ''">无</p>
              <p class="listRight" v-else>{{getGrade(education.grade)}}</p>
            </li>
            <li class="clearfix">
              <p class="listLeft">职称证书</p>
              <p class="listRight" v-if="education.academicImg == 'undefined' || education.academicImg == ''">无</p>
            </li>
            <li v-if="education.academicImg != 'undefined'">
              <img class="showimg" :src="education.academicImg"/>
            </li>
          </ul>
        </TabPane>
        <TabPane label="工作经历">
          <router-link to="/ziliao/job" class="add">
          <Icon type="ios-add" :size="25"/>
            <span>添加工作经历</span></router-link>
          <span v-if="JSON.stringify(works) !== '[]'">
            <ul class="inforList font14" v-for="work in works">
              <li class="clearfix">
                <p class="listLeft">公司名称</p>
                <!--<p class="listRight rightSet">{{work.companyName}}  <span class="suretips" v-if="work.isWork === 1"><img src="../../assets/renzheng.png" alt="" width="70"  ></span><span  v-else class="suretips"><img src="../../assets/norenzheng.png" alt="" width="70"></span></p>-->
                <p class="listRight rightSet">{{work.companyName}}  <!--<span class="suretips" v-if="work.isWork === 1"><img src="../../assets/renzheng.png" alt="" width="70"  ></span><span  v-else class="suretips"><img src="../../assets/nopass.png" alt="" width="70"></span>--></p>
              </li>
              <li class="clearfix">
                <p class="listLeft">职位名称</p>
                <p class="listRight">{{getPosition(work.position)}}</p>
              </li>
              <li class="clearfix">
                <p class="listLeft">业态</p>
                <p class="listRight">{{getOperationType(work.operationType)}}</p>
              </li>
              <li class="clearfix">
                <p class="listLeft">在职时间</p>
                <p class="listRight">{{work.workingLife.text}}</p>
              </li>
              <li class="clearfix">
                <p class="listLeft">工作描述</p>
                <p class="listRight">
                  {{work.workTask}}
                </p>
              </li>
            </ul>
          </span>
          <span v-else>
            <nodata tip="暂时还没有工作经历哦~"></nodata>
          </span>
        </TabPane>
        <Tab-pane label="换绑手机" key="key3" class="changephone">
          <div class="bingPhone font14">
            <p class="phoneText">{{this.person.mobile}}</p>
            <Form inline ref="oldcode">
              <FormItem prop="user">
                <Input  type="text" placeholder="请输入验证码" ref="code2"  @on-keyup="validateCode2" v-model="changeTel.oldCode" :maxlength="6"></Input >
              </FormItem>
              <FormItem>
                <Button @click="getOldCode(person.mobile)" :class="{disabled:changeTel.oldSendUse}">{{changeTel.oldTip}}</Button>
              </FormItem>
            </Form>
          </div>
          <div class="bingPhone font14">
            <p class="phoneText">新手机号</p>
            <Form inline ref="phonecheck1" :model="changeTel" :rules="phoneRule">
              <FormItem prop="newPhone">
                <Input  type="text" ref="phone2"  @on-keyup="validatePhone" placeholder="请输入新手机号" v-model="changeTel.newPhone" :maxlength="11" />
              </FormItem>
            </Form>
            <Form inline ref="ncode" v-bind:model="changeTel">
              <FormItem prop="user" >
                <Input  type="text"  ref="code3"  @on-keyup="validateCode3" placeholder="请输入验证码" v-model="changeTel.newCode" :maxlength="6"/>
              </FormItem>
              <FormItem>
                <Button @click="getNewCode(changeTel.newPhone)" :class="{disabled:changeTel.newSendUse}">{{changeTel.newTip}}</Button>
              </FormItem>
            </Form>
            <Button @click="changeTelephone">换绑</Button>
          </div>
        </Tab-pane>
      </Tabs>
      <Spin fix v-show="isSpinShow" >
        <div class="loader">
          <Icon type="ios-loading" size=26 class="demo-spin-icon-load"></Icon>
          <div class="font14">加载中...</div>
        </div>
      </Spin>
  </div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  /* 旋转效果 */
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50% { transform: rotate(180deg);}
    to { transform: rotate(360deg);}
  }
  /* 假如内容过长，一屏放不下，滚动条下拉覆盖不全 */
  .ivu-spin-fix {
    position: fixed;
  }

  .formWrapper {
    width: 330px;
  }
  .changephone button {
    height: 40px;
  }
  .suretips {
    display: inline-block;
    padding: 0 4px;
    height: 24px;
    /*background-color: #0a3c68;*/
    border-radius: 5px;
    color: #fff;
    text-align: center;
    img{
      vertical-align: middle;
      margin-right: 5px;
    }
  }

  .keepBtn {
    display: inline-block;
    width: 140px;
    height: 48px;
    background-color: #957960;
    text-align: center;
    line-height: 50px;
    color: #fff;
    font-size: 16px;
  }

  .keepBtn:hover {
    cursor: pointer;
  }

  .showimg {
    display: inline-block;
    width: 275px;
    height: 200px;
    overflow: hidden;
    vertical-align: bottom;
  }

  .upuser {
    display: inline-block;
    font-size: 18px;
    color: #333;
    cursor: pointer;
  }

  .keepThis {
    padding: 0 0 0 86px;
  }

  .changeImg {
    padding: 10px 0 20px 0;

    .preimg {
      display: inline-block;
      width: 54px;
      height: 54px;
      overflow: hidden;
      vertical-align: middle;
      border-radius: 50%;
    }

    .upuser {
      display: inline-block;
      width: 90px;
      height: 32px;
      border: 1px solid #957960;
      font-size: 14px;
      color: #957960;
      text-align: center;
      line-height: 30px;
      cursor: pointer;
      margin-left: 20px;

      .ivu-upload {
        width: 100%;
      }
    }

    .upuser:hover {
      background-color: #f1f8fe;
    }
  }

  .add {
    float: right;
    height: 36px;
    text-align: center;
    line-height: 36px;
    border: 1px solid #999;
    border-radius: 18px;
    font-size: 12px;
    padding: 0 10px;
    color: #999;

    span {
      display: inline-block;
    }
  }

  .add:hover {
    border-color: #666;
    background-color: #f9f9f9;
  }

  .inforList {
    padding: 20px 0;
    border-bottom: 1px solid #E1E1E1;

    li {
      margin-bottom: 15px;
      position: relative;

      .listLeft {
        /*font-size: 16px;*/
        color: #666;
        float: left;
      }

      .listRight {
        margin: 0 0 0 90px;
        padding: 0 20px 0 0;
        /*font-size: 16px;*/
        color: #333;
        line-height: 24px;

        .suretips {
          vertical-align: top;
          margin-left: 10px;
        }
      }

      .rightSet {
        margin-right: 70px;
        /*font-size: 16px;*/
        color: #333;
      }

      .editorThis {
        color: #957960;
        padding: 0 0 0 20px;
        height: 22px;
        /*font-size: 16px;*/
        position: absolute;
        right: 0px;
        top: 2px;
        line-height: 20px;
        background: url("../../assets/edit.png") no-repeat left center;
        background-size: 14px;
        cursor: pointer;
      }
    }

    li:last-child {
      margin-bottom: 0px;
    }
  }

  .inforList:last-child {
    border-bottom: none;
  }

  .inforList li .showimg {
    display: block;
    width: 275px;
    height: 200px;
    overflow: hidden;
  }

  .bingPhone {
    margin-top: 30px;
  }

  .bingPhone .ivu-form-item {
    margin-bottom: 20px;
  }

  .bingPhone .phoneText {
    /*font-size: 16px;*/
    color: #333;
    font-weight: 600;
    margin-bottom: 15px;
  }
</style>
<script type="text/ecmascript-6">
  import nodata  from '../template/null'
  import {userDataWeb,updataUserData,educationList,workCourseList,getMobile,sendSms2,verify_smscode_app,changePhone,centreInfoWeb} from '../../http'
  import {getStore,setStore} from "../../storage";

  export default {
    inject: ['reload'],
    props: {},
    data() {
      return {
        isSpinShow:false,
        //手机号码验证规则
        phoneRule:{
          newPhone:[
            {required:true,message:'手机号码不能为空',trigger:''}
          ]
        },
        //头像上传使用
        token:getStore('token'),
        person: {             //个人资料
          avatar: '',       //头像
          userName: '',       //姓名
          nickName: '',       //昵称
          sex: 1,            //性别
          birthday: '',       //生日
          company: '',        //公司
          department: '',     //部门
          positionName: '',   //职位
          mobile: '',      //手机号
          email: '',          //邮箱
        },
        //个人资料表单验证规则
        personValidate:{
          email:[
            {type: 'string',pattern : /^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/ ,message:'邮箱格式不正确',trigger:'blur'}
          ],
        },
        education:'',         //教育经历
        educationList:'',     //教育系列
        professionList:'',    //职位系列
        rankList:'',          //级别系列
        tab:0,                //当前表
        works:'',             //工作经历
        commercials:'',       //业态
        posts:'',             //职位
        workingYears:'',      //工作年限
        //换绑手机号
        changeTel:{
          mobile: '',        //加密过的手机号
          time: '',          //加密时间
          oldCode: '',     //旧手机验证码
          newCode:'',       //新手机验证码
          isVerify: false,   //旧手机号码是否验证通过
          oldTip: '发送验证码',
          oldSendUse: false,          //旧发送验证码是否可用
          oldTimer: '',
          oldTime: 0,                 //旧验证码剩余时间
          newTip: '发送验证码',
          newSendUse:false,         //新发送验证码是否可用
          newPhone: '',
          newTimer: '',           //新手机号定时器
          newTime: 0,                 //新验证码剩余时间
          TIME_COUNT : 60,        //验证码时效
          timer: '',
        }
      };
    },
    methods: {
      validateTel() {
        this.person.mobile = this.$refs.tele.value.replace(/[^\d]{1,11}/g, "")
      },
      //数字输入框
      validatePhone() {
        this.changeTel.newPhone = this.$refs.phone2.value.replace(/[^\d]{1,11}/g, "")
      },
      validateCode2() {
        this.changeTel.oldCode = this.$refs.code2.value.replace(/[^\d]{1,11}/g, "")
      },
      validateCode3() {
        this.changeTel.newCode = this.$refs.code3.value.replace(/[^\d]{1,11}/g, "")
      },
      //是否允许修改教育经历
      editEducation(){
        if(JSON.stringify(this.education) !== '{}'){
          if(this.education.isEducation == 1){
            this.$Notice.warning({
              title: "资料编辑提醒",
              desc: "教育信息已认证，无法修改！",
              duration: 3,
            });
            return;
          }
        }
        this.$router.push({
          name:'jiaoyu'
        })
      },
      //上传头像超出大小2M限制
      handleMaxSize (file) {
        this.$Notice.warning({
          title: '头像上传失败',
          desc: '您上传的图片超过3M，无法上传。'
        });
      },
      formatError(){
        this.$Notice.warning({
          title:"证件上传失败",
          desc:"图片格式错误，请上传图片",
          duration: 3,
        });
      },
      //手机号修改
      changeTelephone(){
        if(this.isSpinShow === false) {
          this.isSpinShow = true;
          //用户是否登录
          centreInfoWeb().then(res => {
            if (res.code === 200) {
              //更换手机号
              changePhone({smsCode: this.changeTel.newCode, mobile: this.changeTel.newPhone}).then(res => {
                if (res.code === 200) {
                  this.$Notice.success({
                    title: '手机号换绑提醒',
                    desc: '手机号换绑成功',
                    duration: 3,
                  });
                  if (this.changeTel.newTimer != null) {
                    clearInterval(this.changeTel.newTimer);
                    this.changeTel.newTip = '发送验证码';
                    this.changeTel.newSendUse = false;
                    this.changeTel.newTimer = null;
                  }
                  if (this.changeTel.oldTimer != null) {
                    clearInterval(this.changeTel.oldTimer);
                    this.changeTel.oldTip = '发送验证码';
                    this.changeTel.oldSendUse = false;
                    this.changeTel.oldTimer = null;
                  }
                  userDataWeb().then(res => {
                    if(res.code === 200) {
                      this.isSpinShow = false;
                      this.person = res.data;
                      this.changeTel.oldCode = '';
                      this.changeTel.newCode = '';
                      this.$refs['phonecheck1'].resetFields();
                    }else {
                      this.isSpinShow = false;
                      this.$Notice.warning({
                        title: "个人中心提醒",
                        desc: res.info,
                        duration: 3,
                      });
                    }
                  }).catch();
                }else {
                  this.isSpinShow = false;
                  this.$Notice.warning({
                    title: "手机号换绑提醒",
                    desc: res.info,
                    duration: 3,
                  });
                }
              }).catch()
            } else {
              this.isSpinShow = false;
              this.$parent.$refs.loginInput.showModal()
            }
          }).catch()
        }
      },
      //旧手机号获取验证码
      getOldCode(phone){
        getMobile({mobile:phone}).then(res => {
          if(res.code === 200){
            this.changeTel.mobile = res.data.mobile;
            this.changeTel.time = res.data.time;
            if (!this.changeTel.timer) {
              //获取验证码
              sendSms2({mobile:this.changeTel.mobile,time:this.changeTel.time}).then(res => {
                if(res.code === 200){
                  //成功获得验证码
                  // this.changeTel.oldCode = res.data;
                  //旧验证码再次发送，定时器创建
                  this.changeTel.oldTime = this.changeTel.TIME_COUNT;         //时间设定为总时间
                  this.changeTel.oldSendUse = true;                          //按钮不可用
                  this.changeTel.oldTimer = setInterval(() => {               //创建定时器
                    if (this.changeTel.oldTime > 0 && this.changeTel.oldTime <= this.changeTel.TIME_COUNT) {
                      this.changeTel.oldTip = this.changeTel.oldTime +'s重新发送验证码';   //验证码提示
                      this.changeTel.oldTime --;                //计时减
                    } else {
                      clearInterval(this.changeTel.timer);      //清除定时器同时重置提示信息，和按钮是否可用
                      this.changeTel.oldTip = '发送验证码';
                      this.changeTel.oldSendUse = false;         //按钮可用
                      this.changeTel.timer = null;
                    }
                  }, 1000)
                }else{
                  this.$Notice.warning({
                    title: "验证码提醒",
                    desc: res.info,
                    duration: 3,
                  });
                }
              }).catch();
            }
          }
        }).catch()
      },
      getNewCode(phone){
        //校验验证码
        verify_smscode_app({mobile:this.person.mobile,smsCode:this.changeTel.oldCode}).then(res => {
          if (res.code == 200){
            this.changeTel.isVerify = true;
          }else{
            this.changeTel.isVerify = false;
          }
        }).catch();
        //旧手机号验证
        if(this.changeTel.isVerify) {           //旧验证码是否正确
          this.$refs['phonecheck1'].validate((valid) => {        //判断新手机号码是否填写
            if(valid) {                  //新手机号码已填写
              getMobile({mobile: this.changeTel.newPhone}).then(res => {
                if (res.code === 200) {
                  this.changeTel.mobile = res.data.mobile;
                  this.changeTel.time = res.data.time;
                  //获取验证码
                  sendSms2({
                    mobile: this.changeTel.mobile,
                    time: this.changeTel.time,
                  }).then(res => {
                    if (res.code === 200) {
                      // this.changeTel.newCode = res.data;
                      this.changeTel.newTime = this.changeTel.TIME_COUNT;         //新验证码计时设为总时间
                      this.changeTel.newSendUse = true;                          //新验证码发送按钮禁用
                      this.changeTel.newTimer = setInterval(() => {
                        if (this.changeTel.newTime > 0 && this.changeTel.newTime <= this.changeTel.TIME_COUNT) {
                          this.changeTel.newTip = this.changeTel.newTime + 's重新发送验证码';
                          this.changeTel.newTime--;
                        } else {
                          clearInterval(this.changeTel.timer);
                          this.changeTel.newTip = '发送验证码';
                          this.changeTel.newSendUse = false;
                          this.changeTel.timer = null;
                        }
                      }, 1000)
                    } else {
                      this.$Notice.warning({
                        title: "验证码提醒",
                        desc: res.info,
                        duration: 3,
                      });
                    }
                  }).catch();
                }
              }).catch()
            }
          }).catch()
        }
      },
      getEducation(code){
        let edus = this.educationList;
        for(let i = 0; i < edus.length; i++){
          if(edus[i].code === code){
            return edus[i].name;
          }
        }
      },
      getMajor(code){
        let pros = this.professionList;
        for(let i = 0; i < pros.length; i++){
          if(pros[i].code === code){
            return pros[i].name;
          }
        }
      },
      getGrade(code){
        let ranks = this.rankList;
        for(let i = 0; i < ranks.length; i++){
          if(ranks[i].code === code){
            return ranks[i].name;
          }
        }
      },
      getOperationType(code){
        let operations = this.commercials;
        for(let i = 0 ;i < operations.length; i++){
          if(operations[i].code === code){
            return operations[i].name;
          }
        }
      },
    /*  getworkingLife(code){
        let lifes = this.workingYears;
        for(let i = 0; i < lifes.length;i++){
          if(lifes[i].name === code){
            return lifes[i].text;
          }
        }
      },*/
      getPosition(code){
        let posts = this.posts;
        for (let i = 0; i < posts.length; i++){
          if(posts[i].code === code){
            return posts[i].name;
          }
        }
      },
      //头像上传
      headSuccess (response) {
        this.$set(this.person,'avatar',response.data.fileUrl);
      },
      //切换标签页
      changeTab(tab){
        if(this.isSpinShow === false) {
          this.isSpinShow = true;
          if (tab === 1) {
            //用户是否登录
            centreInfoWeb().then(res => {
              if (res.code === 200) {
                if(!res.data.education){
                  this.$router.push({
                    name:'jiaoyu'
                  })
                }
                //获取教育经历
                educationList().then(res => {
                  if(res.code === 200) {
                    this.isSpinShow = false;
                    this.education = res.data.education;
                    this.educationList = res.data.educationList;
                    this.rankList = res.data.rankList;
                    this.professionList = res.data.professionList;
                  }else {
                    this.isSpinShow = false;
                    this.$Notice.warning({
                      title: "个人中心提醒",
                      desc: res.info,
                      duration: 3,
                    });
                  }
                }).catch();
              } else {
                this.isSpinShow = false;
                this.$parent.$refs.loginInput.showModal()
              }
            }).catch()
          } else if (tab === 2) {
            //用户是否登录
            centreInfoWeb().then(res => {
              if (res.code === 200) {
                //获取工作经历列表
                workCourseList().then(res => {
                  if(res.code === 200) {
                    this.isSpinShow = false;
                    this.works = res.data.list;
                    this.posts = res.data.posts;
                    this.workingYears = res.data.workingYears;
                    this.commercials = res.data.commercials;
                  }else {
                    this.isSpinShow = false;
                    this.$Notice.warning({
                      title: "个人中心提醒",
                      desc: res.info,
                      duration: 3,
                    });
                  }
                }).catch();
              } else {
                this.isSpinShow = false;
                this.$parent.$refs.loginInput.showModal()
              }
            }).catch()
          } else {
            //用户是否登录
            centreInfoWeb().then(res => {
              if (res.code === 200) {
                //获取用户基本信息
                centreInfoWeb().then(res => {
                  if(res.code === 200) {
                    this.isSpinShow = false;
                    this.person = res.data;
                    if(this.person.sex == '' || this.person.sex == null || this.person.sex == undefined){
                      this.person.sex = 1;
                    }
                  }else {
                    this.isSpinShow = false;
                    this.$Notice.warning({
                      title: "个人中心提醒",
                      desc: res.info,
                      duration: 3,
                    });
                  }
                });
              } else {
                this.isSpinShow = false;
                this.$parent.$refs.loginInput.showModal()
              }
            }).catch()
          }
        }
      },
      //修改个人资料
      updateUserData(){
        if(this.isSpinShow === false) {
          this.isSpinShow = true;
          this.$refs['personValidate'].validate((valid) => {
            if (valid) {
              //用户是否登录
              centreInfoWeb().then(res => {
                if (res.code === 200) {
                  //修改用户资料
                  updataUserData({
                    avatar: this.person.avatar,
                    userName: this.person.userName,
                    nickName: this.person.nickName,
                    sex: this.person.sex,
                    birthday: this.person.birthday,
                    mobile: this.person.mobile,
                    email: this.person.email
                  }).then(res => {
                    if (res.code === 200) {
                      //修改了个人头像，重新获取头像，同时缓存到页面
                      centreInfoWeb().then(res => {
                        if (res.code === 200) {
                          this.isSpinShow = false;
                          this.person = res.data;
                          setStore('person', this.person);
                          this.$Notice.success({
                            title: '个人资料提醒',
                            desc: '个人资料修改成功!',
                            duration: 3,
                          });
                        }else {
                          this.isSpinShow = false;
                          this.$Notice.warning({
                            title: "个人中心提醒",
                            desc: res.info,
                            duration: 3,
                          });
                        }
                      }).catch()
                      this.reload();
                    } else {
                      this.isSpinShow = false;
                      this.$Notice.warning({
                        title: "个人资料提醒",
                        desc: "个人资料保存失败",
                        duration: 3,
                      });
                    }
                  }).catch();
                } else {
                  this.isSpinShow = false;
                  this.$parent.$refs.loginInput.showModal()
                }
              }).catch()
            }else {
              this.isSpinShow = false;
            }
          })
        }
      },
      getBirthday(value){
        this.person.birthday = value;
      },
      getZiliao(){
        if(this.isSpinShow === false) {
          this.isSpinShow = true;
          //用户是否登录
          centreInfoWeb().then(res => {
            if (res.code === 200) {
              //获取用户资料
              centreInfoWeb().then(res => {
                if(res.code === 200) {
                  this.isSpinShow = false;
                  this.person = res.data;
                  if(this.person.sex == '' || this.person.sex == null || this.person.sex == undefined){
                    this.person.sex = 1;
                  }
                }else {
                  this.isSpinShow = false;
                  this.$Notice.warning({
                    title: "个人中心提醒",
                    desc: res.info,
                    duration: 3,
                  });
                }
              }).catch();
              this.$parent.getInfo();
            }else {
              this.isSpinShow = false;
            }
          }).catch()
        }
      }
    },
    created(){
      this.getZiliao()
    },
    components: {
      nodata
    },
  }
</script>
